package com.arvinclub.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未登录拦截
 */
@WebFilter(filterName = "userFilter",urlPatterns = "/user/*")
public class userFilter implements Filter
{
    public void destroy(){}

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException
    {
        if (((HttpServletRequest) req).getSession().getAttribute("user") != null)
            chain.doFilter(req, resp);
        else
            ((HttpServletResponse)resp).sendRedirect("/");
    }

    public void init(FilterConfig config){ }

}
